package com.zmn.plat.services.impl.company;

import com.zmn.common.dto.VtDTO;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.plat.common.exception.PlatException;
import com.zmn.plat.services.interfaces.company.BaseCompanyAreaService;
import com.zmn.sp.common.enums.available.AvailableAreaLevelEnum;
import com.zmn.sp.dubbo.interfaces.available.AvailableAreaListRemoteService;
import com.zmn.sp.dubbo.utils.DubboConsts;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * @author duanzuocai
 * @version v1.0
 * @类说明：公司覆盖区域
 * @since 2018/11/1 9:25
 */
@Service
public class BaseCompanyAreaServiceImpl implements BaseCompanyAreaService {

    private Logger logger = LoggerFactory.getLogger(BaseCompanyAreaServiceImpl.class);

    @Reference(version = DubboConsts.INTERFACE_VERSION,check = false)
    private AvailableAreaListRemoteService availableAreaListRemoteService;

    @Override
    public List<VtDTO> listVtByManageCompanyId(Integer manageCompanyId) {
        ResponseDTO<List<VtDTO>> listResponseDTO = availableAreaListRemoteService.listAvailableAreaBySpId(manageCompanyId, AvailableAreaLevelEnum.CITY);
        if (!listResponseDTO.isSuccess()) {
            throw new PlatException("调用服务商接口出错");
        }

        return Optional.ofNullable(listResponseDTO.getData()).orElse(Collections.emptyList());
    }


}
